<template>
  <div class="lu-editor">
    <vue-editor v-model="value" @image-added="imgAdd" :useCustomImageHandler="true" />
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor"
export default {
  name: 'lu-editor',
  components: {
    VueEditor
  },
  props: {
    
  },
  computed: {
    value: {
      get () {
        return this.$attrs.defaultValue
      },
      set (v) {
        this.$emit('EventHandler', 'change', this.$attrs.prop, v);
      }
    }
  },
  methods: {
    async imgAdd (file, Editor, cursorLocation, resetUploader) {
      console.log(file, Editor, cursorLocation)
      let form = new FormData()
      form.append('file', file)
      let data = await this.Lushu.upload(form)
      Editor.insertEmbed(cursorLocation, "image", data);
      resetUploader()
    }
  }
}
</script>
